Skip to content

Claim scope limits only for controllers the user manager was delegated - #156

Merged
M3gA-Mind merged 5 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/p3-scope-limits-probe
Nov 12, 2026
Merged

M3gA-Mind merged 5 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/p3-scope-limits-probe

Conversation

@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Summary

The 2.1 native resource jail (StartJailedExecWithResources) claimed CPU, memory and pid limits as Enforced once a trusted systemd-run and bwrap were on disk. The limits are applied by the user's own systemd manager. That manager has to be reachable, and it can only set a limit for a cgroup controller it was delegated. Without either, a scope fails to start or runs with the limit missing.

New tinybox_linux::ScopeProbe reads both:

  • whether the manager's socket ($XDG_RUNTIME_DIR/systemd/private, or the session bus socket) exists;
  • which controllers /sys/fs/cgroup/user.slice/user-<uid>.slice/user@<uid>.service/cgroup.controllers lists.

The resource backend now claims Cpu, Memory and Pids only for delegated controllers. A requested limit whose controller is missing is refused with UnsupportedOperation before anything starts, never dropped.

Stacked on #154 (merge it first).

Related issue

Part of #27 (enforcement gaps: claimed versus enforced resource limits).

API or behavior changes

  • New tinybox_linux::ScopeProbe (detect, from_parts, constraint_support).
  • On a host whose user manager lacks a controller (for example cgroup v1, or a systemd that doesn't delegate cpu), a 2.1 request for that limit is now refused where it was accepted before.
  • Requests with resources on the legacy jail members stay refused, as today, since they require a disk limit no backend enforces. Routing them through the scope follows once disk_bytes is optional.
  • No bus contract change.

Validation

On our Linux CI runner (user manager delegating cpu memory pids, $XDG_RUNTIME_DIR/systemd/private a socket), at c100cea:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --all-targets --all-features -- -D warnings: 0 errors, same as main.
  • cargo build and RUSTDOCFLAGS="-D warnings" cargo doc: ok.
  • cargo test -p tinybox-linux probe::scope: 4 passed.
  • cargo test -p tinybox-module native_jail: 22 passed. The live native-resource tests ran (none skipped) and still pass with the probe in place.
  • cargo test -p tinybox-linux -p tinybox-module -p tinybox-microvm: no failures, the same as main.
  • Red controls, each restored afterwards:
    • removing the refusal: the module test fails ("a pids limit with no pids controller must be refused");
    • reading cpu from the manager alone: both probe tests fail.

Tests

  • probe::scope:
    • each limit follows its own controller;
    • nothing is claimed without a reachable manager, or without a delegated cgroup;
    • cpuset doesn't count as cpu.
  • a_limit_whose_controller_is_not_delegated_is_refused_not_dropped: with cpu and memory delegated but not pids, a request with a pids limit is refused and the command is left untouched. Everything else in the request is acceptable, so only the missing controller can refuse it.
  • The live native-resource tests still run on a host with full delegation.
  • Red controls: dropping the refusal fails the module test, and reading cpu from the manager alone fails the probe tests.

Documentation

docs/specs/constraint-preflight.md (the native resource jail row and note). Rustdoc on ScopeProbe.

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

A trusted systemd-run on disk was taken as proof that the 2.1 native resource
jail enforces CPU, memory and pid limits. The limits are applied by the user's
systemd manager, which must be reachable and must have been delegated each
cgroup controller; without that a scope fails to start or runs without the
limit.

tinybox_linux::ScopeProbe reads the manager's socket and the controllers
delegated to user@<uid>.service. The resource backend claims Cpu, Memory and
Pids from it, and a requested limit whose controller is missing is refused
before anything starts.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ecd9e67-a8be-497f-9bca-b41c8c500aa0
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@M3gA-Mind

Copy link
Copy Markdown
Collaborator Author

This branch is stacked on #154 (its first two commits are #154's). Please merge #154 first; this PR's diff then reduces to the scope-probe commit.

@tinysweeper

tinysweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: d1e3907eb970d03772f4259c860e3f0c110fddb2

Verdict: Ready for maintainer review · Priority: low
Coverage: Reviewed 7 of 7 files.
Pull request purpose (title): Claim scope limits o…

Diagnostics and supporting details

Full summary

Pull request purpose (title): Claim scope limits only for controllers the user manager was delegated. Purpose (title): Claim scope limits only for controllers the user manager was delegated. The pull request stops the 2.1 native resource jail (`StartJailedExecWithResources`) from claiming CPU, memory and pid limits as enforced merely because a trusted `systemd-run` and `bwrap` exist on disk: those limits are applied by the user's own systemd manager, which must be running and reachable and must have been delegated the relevant cgroup controller, otherwise a scope either fails to start or starts with the limit silently missing. It adds `tinybox_linux::ScopeProbe`, which reads the manager socket (`$XDG_RUNTIME_DIR/systemd/private` or the session bus socket) and the user manager's `cgroup.controllers`, and the resource backend now claims `Cpu`, `Memory` and `Pids` only for delegated controllers, refusing an unenforceable requested limit with `UnsupportedOperation` before anything starts rather than dropping it. The same diff also downgrades the native jail's `Subprocess` claim to `Unsupported`, makes its kernel-isolation claim conditional on `bwrap` supporting `--disable-userns` (adding that flag to the argv), and makes the MicroVM backend refuse any egress policy at create.

Review snapshot

Change surface Files Review signal Count
Production 4 Active findings 0
Tests 2 Noted findings 0
Documentation 1 Resolved findings 0
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: Test coverage is assessed from changed tests and lane evidence; execution is not claimed without trusted check data.

What changed

The 2.1 native resource jail's claimed resource support is now derived from a host probe instead of assumed. `tinybox_linux::ScopeProbe` (`detect`, `from_parts`, `constraint_support`) reads the user manager socket under `$XDG_RUNTIME_DIR` (or a `unix:path=` session bus address) plus the user manager's `cgroup.controllers` file, and maps `cpu`, `memory` and `pids` to `Enforced` only when a manager is reachable and that exact controller name is listed. The backend holds that probe (`with_scope` for injection, `detect` by default), reports `Cpu`/`Memory`/`Pids` from it, and refuses a request carrying a limit whose controller is not delegated, returning the unsupported-operation error before binding resources or touching the command. The backend's `Subprocess` claim moves from `Enforced` to `Unsupported`, and its isolation level becomes `Kernel` only when the probed `bwrap` supports `--disable-userns` and `None` otherwise, with that flag threaded into `NativeJailCommand` and emitted by the argv builder on the bwrap side only when requested. The MicroVM backend now refuses any network policy that allows egress, since the VM has no network interface, instead of only refusing an allowlist. Documentation's preflight table gains a native-resource-jail row and a note, but that row still lists Subprocess as Enforced while the code reports `Unsupported`. The latest-push delta is unavailable: only the prior reviewed head and the current head are known, with no trusted base-to-head comparison.

Features

  • Added — ScopeProbe for user-manager and cgroup-controller delegation: A requested CPU, memory or pid limit is claimed as `Enforced` only when the user's systemd manager is reachable and was delegated that controller; otherwise the claim is `Unsupported`. (crates/tinybox-linux/src/probe/scope.rs, crates/tinybox-linux/src/lib.rs, crates/tinybox-linux/src/probe/mod.rs)
  • Modified — Native resource jail refuses limits its scope cannot apply: A request whose CPU, memory or pid limit has no delegated controller fails with the unsupported-operation error before spawn and is never silently dropped; previously such a request was accepted. (crates/tinybox-module/src/tinybus_module/native_jail.rs fn prepare_with_resources(, crates/tinybox-module/src/tinybus_module/native_jail.rs fn unavailable() -> Error {)
  • Modified — Native resource jail drops its Enforced subprocess claim: The backend now reports `Subprocess` as `Unsupported` rather than `Enforced`, changing what callers are told the jail guarantees. (crates/tinybox-module/src/tinybus_module/native_jail.rs impl JailBackend for NativeResourceBackend {)
  • Modified — Kernel isolation claim gated on bwrap --disable-userns: The backend reports `Kernel` isolation only for a probed bwrap that supports `--disable-userns` and `None` otherwise; on a host with an older bwrap the backend drops from `Kernel` to `None` and is no longer suitable for untrusted code. (crates/tinybox-module/src/tinybus_module/native_jail.rs impl JailBackend for NativeResourceBackend {)
  • Added — --disable-userns argv flag: `NativeJailCommand` gains a `disable_userns` field that appends `--disable-userns` to the native bwrap argv after systemd-run's `--`, so a child can be barred from creating new user namespaces; it is only emitted when set, since an older bwrap rejects the flag. (crates/tinybox-module/src/tinybus_module/native_jail.rs impl JailBackend for NativeResourceBackend {)
  • Modified — MicroVM refuses any egress at creation: Any network policy that allows egress is rejected at `create` with a network `ConstraintNotEnforced` error, because the VM has no network interface; only a denied policy is accepted. (crates/tinybox-module/src/tinybus_module/native_jail.rs impl JailBackend for NativeResourceBackend {)
  • Modified — Constraint preflight documentation for the native resource jail: The support table gains a native resource jail row and a note tying claimed limits to manager delegation, subprocess allowance, `--disable-userns` and the MicroVM egress refusal, but the new row lists Subprocess as Enforced while the code reports `Unsupported`. (docs/specs/constraint-preflight.md coarse lifecycle capabilities do not imply resource enforcement.)

Tests

  • test gap for the bwrap --disable-userns probe — The new `BubblewrapBackend::disables_userns` accessor is not exercised directly by any test.: The tests lane, which answered, did not raise this as a defect, noting the behaviour is transitively pinned by the native-jail isolation test; no test exercises it directly. (crates/tinybox-module/src/tinybus_module/native_jail.rs impl JailBackend for NativeResourceBackend {)

Findings

No active actionable findings.

Before merge

None.

How this fits together

flowchart LR
  n0["NativeResourceBackend<br/>changed"]:::changed
  n1["prepare_with_resources<br/>changed"]:::changed
  n2["unavailable<br/>changed"]:::changed
  n3["..._resource_limits_are_refused_before_spawn<br/>changed"]:::changed
  n4["tempdir"]:::impacted
  n5["resource_backend"]:::impacted
  n6["...r_is_not_delegated_is_refused_not_dropped"]:::impacted
  n7["config"]:::impacted
  n8["...target_environment_off_every_command_line"]:::impacted
  n9["...d_descendants_and_preserves_stream_events"]:::impacted
  n1 -->|uses| n0
  n1 -->|calls| n2
  n3 -->|calls| n4
  n3 -->|tests| n4
  n3 -->|calls| n7
  n3 -->|tests| n7
  n5 -->|uses| n0
  n6 -->|uses| n0
  n6 -->|calls| n1
  n6 -->|tests| n1
  n6 -->|calls| n4
  n6 -->|tests| n4
  n6 -->|calls| n7
  n6 -->|tests| n7
  n8 -->|calls| n1
  n8 -->|tests| n1
  n8 -->|calls| n4
  n8 -->|tests| n4
  n8 -->|calls| n5
  n8 -->|tests| n5
  n8 -->|calls| n7
  n8 -->|tests| n7
  n9 -->|calls| n1
  n9 -->|tests| n1
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 4 files; 1 finding.

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The security lane answered, completing review of its files with no findings; the specification document was excluded as prose or tabular data.
  • Lane summary: Reviewed 3 files; 0 findings. 1 file was not security-reviewed: docs/specs/constraint-preflight.md (prose or tabular data).

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The tests lane answered with no pending checks and found no reportable defect; the new test exercises the refusal and asserts the target argv is left untouched, so the refusal behaviour is pinned.
  • Lane summary: The change makes the native resource backend's CPU/memory/pids support follow the delegated cgroup controllers, refuses a requested limit the scope cannot apply, and adds a test for that refusal path; the new test exercises the refusal and asserts the target argv is left untouched, so the behaviour is pinned. I found no reportable defect in the reviewed diff.

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The commits lane answered and reported no sensitive content in the committed files.
  • Lane summary: No sensitive content in committed files.

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The description lane answered and reported that the description names the new `ScopeProbe`, the delegation/manager gating, the refusal for a limit whose controller is missing, and the doc table update, and found nothing it misstates or omits that the diff actually does.
  • Lane summary: The description matches the diff: it names the new `tinybox_linux::ScopeProbe`, the delegation/manager gating, the refusal for a limit whose controller is missing, and the doc table update. I checked `ConstraintSupport::enforcement`, `prepare_with_resources`, `unavailable()` and the new test, and found nothing the description misstates or omits that the diff actually does. One caveat I could not verify: the body claims `tinybox-module` and `tinybox_linux` changes are all present, and the `tinybox-module` half is what the second commit adds; the `ScopeProbe` wiring in `native_jail.rs` (refusal + `constraint_support`) is exactly what the body describes, so the description is accurate.
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash, deepseek-v4-flash
  • Spend: $0.013629
  • Completion usage: incomplete; some provider completion costs are unavailable.
  • Tokens: 529284 input · 30817 output · 72470 cached · 457 embedding
  • Updated: 2026-11-12T15:35:22Z
  • Continuity: summary cache chain restarted at the storage ceiling.
Head State Pass summary
c100cead20ab ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-11-11T11:53:30Z)
fbd8d9413939 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-11-11T14:18:51Z)
381104b39ae1 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-11-12T06:55:19Z)
d1e3907eb970 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-11-12T15:35:22Z)

tinysweeper 0.1.2

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0634

@tinysweeper tinysweeper Bot added the priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. label Nov 11, 2026
@tinysweeper tinysweeper Bot added priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. and removed priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. labels Nov 12, 2026
# Conflicts:
#	crates/tinybox-module/src/tinybus_module/native_jail.rs

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0136

@M3gA-Mind
M3gA-Mind merged commit 45e68ff into tinyhumansai:main Nov 12, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant